home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-06-10 | 11.2 KB | 631 lines | [TEXT/QED1] |
- ( === Compiler support words. === )
-
- #ifndef _COMPATIBILITY_
- #define _COMPATIBILITY_
-
- #ifndef _RECORDS_
- INCLUDE" :Includes:Record_Defs.4th"
- #endif
-
- #ifndef _MacTypes_
- INCLUDE" :Includes:MacTypes.4th.inc"
- #endif
-
- #ifndef _APPLETALK_
- INCLUDE" :Includes:AppleTalk.4th.inc"
- #endif
-
- #ifndef _TEMPMEM_
- INCLUDE" :Includes:TempMem.4th"
- #endif
-
- #ifndef _SYSEQU_
- INCLUDE" :Includes:SysEqu.Txt"
- #endif
-
- save.VOCAB.state
- ONLY FORTH
- ALSO ASSEMBLER
- ALSO MAC DEFINITIONS
-
- #ifdef _EMBEDDED_
- .( Mac Compatibility testing words compiled for embedded code applications.)
- CR
- #endif
-
- DECIMAL
-
- : ,NEWOS ( set bit 9, clear bit 10 - for OS GetTrapAddress calls )
- HERE 2- DUP
- W@ $0200 OR $FBFF AND
- SWAP W!
- ;
- IMMEDIATE
-
-
- : ,NEWTOOL ( set bit 9 and 10 - for ToolBox GetTrapAddress calls )
- HERE 2- DUP
- W@ $0600 OR
- SWAP W!
- ;
- IMMEDIATE
-
- .TRAP _UnknownTrap $A89F
- .TRAP _Unimplemented $A89F
- .TRAP _SysEnvirons $A090
- .TRAP _Gestalt $A1AD
-
- $9F CONSTANT UnknownTrap.#
- $9F CONSTANT Unimplemented.#
- $90 CONSTANT SysEnvirons.#
- $1AD CONSTANT Gestalt.#
-
- $A89F CONSTANT UnknownTrap
- $A89F CONSTANT Unimplemented
- $A090 CONSTANT SysEnvirons
- $A1AD CONSTANT Gestalt
-
- ( ===== System Globals ===== )
-
- $12F CONSTANT CPUFlag ( byte )
- $21E CONSTANT KbdType ( byte )
- $291 CONSTANT PortBUse
- $A58 CONSTANT SysMap ( global that contains System Map reference # )
- $B22 CONSTANT HWCfgFlags
- $B22 CONSTANT SCSIFlags
-
- ( ===== System Global Constants ===== )
-
- 15 CONSTANT SCSI.port.present.bit
- $8000 CONSTANT SCSI.port.present.mask
- 14 CONSTANT New.Clock.Chip.Present.bit
- $4000 CONSTANT New.Clock.Chip.Present.mask
- 13 CONSTANT Extra.PRAM.Valid.bit
- $2000 CONSTANT Extra.PRAM.Valid.mask ( at boottime )
- 4 CONSTANT has.FPU.bit ( in HwCfgFlags )
- $0010 CONSTANT has.FPU.mask
-
- 0 CONSTANT OSTrap
- 1 CONSTANT ToolTrap
-
- ( ===== SysEnviron record constants ===== )
-
- :RECORD SysEnvRec
- environsVersion short
- machineType short
- systemVersion short
- processor short
- hasFPU char
- hasColorQD char
- keyBoardType short
- atDrvrVersNum short
- sysVRefNum short
- ;RECORD
-
- CODE NGetTrapAddress.Tool
- ( trap# -- addr )
- MOVE.W 2(A6),D0
- _GetTrapAddress ,NEWTOOL
- MOVE.L A0,(A6)
- RTS
- END-CODE MACH
-
- CODE NGetTrapAddress.OS
- ( trap# -- addr )
- MOVE.W 2(A6),D0
- _GetTrapAddress ,NEWOS
- MOVE.L A0,(A6)
- RTS
- END-CODE MACH
-
- : NumToolboxTraps ( -- number )
- $6E NGetTrapAddress.Tool ( _InitGraf )
- $AA6E NGetTrapAddress.Tool
- =
- IF $200 ELSE $400 THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- ( I had to comment out this word, because the edge compiler corrupted
- the flow when the macro compilation is used. Apparently, when one
- word ends like
-
- " … IF constant1 ELSE constant2 THEN ;"
-
- and is macro'ed into the sequence
-
- " … word1 -> lvar2 …"
-
- the edge optimizer steps on the … ELSE … THEN stack push and the
- branch after constant1 is incorrect. I will have to watch out for this.
- This shows why edge compilers sometimes suck.
-
- : GetTrapType ( trap -- traptype )
- $0800
- AND
- 0>
- IF ToolTrap ELSE OSTrap THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- )
-
- CODE GetTrapType
- MOVE.L (A6)+,D0
- BTST #11,D0
- BEQ.S @itsanOSTrap
-
- MOVEQ.L #ToolTrap,D0
- BRA.S @flagonstack
-
- @itsanOSTrap
- MOVEQ.L #OSTrap,D0
-
- @flagonstack
- MOVE.L D0,-(A6)
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : TrapAvailable? { trap.# | trapType -- flag }
-
- trap.# GetTrapType -> trapType
- trapType ToolTrap =
- IF
- trap.#
- $07FF AND
- -> trap.#
- trap.# NumToolboxTraps
- < NOT
- IF
- UnknownTrap -> trap.#
- THEN
- THEN
- trap.#
- trapType ToolTrap =
- IF
- NGetTrapAddress.Tool
- ELSE
- NGetTrapAddress.OS
- THEN
- UnknownTrap NGetTrapAddress.Tool
- = NOT
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : is.Gestalt.Avail
- ( -- flag )
- Gestalt TrapAvailable?
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : is.SysEnvirons.Avail
- ( -- flag )
- SysEnvirons TrapAvailable?
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- CODE (CALL).Gestalt
- ( OSType @response -- result )
- MOVE.L 4(A6),D0
- MOVE.L (A6),A0
- ADDQ.W #4,A6
- _Gestalt
- EXT.L D0
- MOVE.L D0,(A6)
- RTS
- END-CODE MACH
-
- CODE CALL.Gestalt
- ( OSType @response -- result )
- EXG D4,A7
- MOVE.L 4(A6),D0
- MOVE.L (A6),A0
- ADDQ.W #4,A6
- _Gestalt
- EXT.L D0
- MOVE.L D0,(A6)
- EXG D4,A7
- RTS
- END-CODE MACH
-
- ( here is included code to execute when SysEnvirons is not available )
-
- : setenvironsVersion
- ( -- version )
- 1
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : setmachineType
- ( -- n )
-
- ROMBase @ 9 + C@ $FF
- = NOT
- IF
- ( it is not a MAC XL )
- ROM85 W@ $8000 AND
- 0=
- IF
- ( it is a 512KE or better -
- if it has the new clock chip it is a Mac Plus )
- HWCfgFlags W@ New.Clock.Chip.Present.mask AND
- 0=
- IF
- ( new clock chip is not present - a 512KE )
- 1
- ELSE
- ( at least a Plus )
- ( test for Mac SE or Mac II )
- ROMBase @ 8 + W@
- CASE
- $75 OF 2 ENDOF ( a MAC Plus )
- $76 OF 3 ENDOF ( a MAC SE )
- $78 OF 4 ENDOF ( a Mac II )
- ( else it is an unknown Mac )
- 0 SWAP
- ENDCASE
- THEN
- ELSE
- ( it's a 128 or 512K Mac)
- -1
- THEN
- ELSE
- ( it is a Lisa )
- -2
- THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : set.System.Version
- ( -- n )
- ( if this routine is called, it is because SysEnvirons doesn't exist,
- so we can safely zero the System Version field )
-
- 0
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : set.processor.type
- ( -- n )
- CPUFlag C@ 3 >
- IF
- 0
- ELSE
- CPUFlag C@ 1+
- THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : set.FPU.exist
- ( -- n )
- HWCfgFlags W@ has.FPU.mask AND
- 0=
- IF
- 0
- ELSE
- 1
- THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- CODE set.Color.QD.exist
- ( -- n )
- MOVE.W ROM85,-(A6)
- CMPI.W #$3FFF,(A6)
- BHI.S @noCQD
-
- MOVE.W #1,(A6)
- BRA.S @addpad
-
- @noCQD
- CLR.W (A6)
- @addpad
- CLR.W -(A6)
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- ( Comparing keyboard type in KbdType, and the value returned by SysEnvirons
-
- KbdType $03 $13 $0B $02 $01 $06 $07 $04 $05 $08 $09
- | | | | | | | | | | |
- SysEnvirons $01 $02 $03 $04 $05 $06 $07 $08 $09 $0A $0B
- | | | | | | | | | | |
- | | | | | | | | | | Apple Keyboard II (ISO)
- | | | | | | | | | Apple Keyboard II
- | | | | | | | | Apple Extended Keyboard (ISO)
- | | | | | | | Apple Standard Keyboard (ISO)
- | | | | | | Portable Keyboard (ISO)
- | | | | | Portable Keyboard
- | | | | standard Apple Desktop Bus keyboard
- | | | Apple extended Kbd
- | | Macintosh Plus keyboard
- | Macintosh keyboard and keypad
- Macintosh keyboard
- )
-
- ( SysEnvirons returned constants )
- 0 CONSTANT envUnknownKbd ( Macintosh Plus keyboard with keypad )
- 1 CONSTANT envMacKbd ( Macintosh keyboard )
- 2 CONSTANT envMacAndPad ( Macintosh keyboard and keypad )
- 3 CONSTANT envMacPlusKbd ( Macintosh Plus keyboard )
- 4 CONSTANT envAExtendKbd ( Apple extended Kbd )
- 5 CONSTANT envStandADBKbd ( standard Apple Desktop Bus keyboard )
- 6 CONSTANT envPortADBKbd ( Portable Keyboard )
- 7 CONSTANT envPortISOADBKbd ( Portable Keyboard (ISO) )
- 8 CONSTANT envStdISOADBKbd ( Apple Standard Keyboard (ISO) )
- 9 CONSTANT envExtISOADBKbd ( Apple Extended Keyboard (ISO) )
- 10 CONSTANT envADBKbdII ( Apple Keyboard II )
- 11 CONSTANT envADBISOKbdII ( Apple Keyboard II (ISO) )
-
- 11 CONSTANT no.of.kbds
-
- CODE get.keyboard.type
- ( -- type )
- BRA.S @dokb
-
- ( Compile a CONSTANT array of keyboard types )
- DC.B $03
- DC.B $13
- DC.B $0B
- DC.B $02
- DC.B $01
- DC.B $06
- DC.B $07
- DC.B $04
- DC.B $05
- DC.B $08
- DC.B $09
- .ALIGN
- @dokb
- LEA -2(PC),A0
- MOVE.B KbdType,D0 \ get current keyboard type
- MOVE.W #no.of.kbds,D1
- SUBQ.W #1,D1
- @next.type
- CMP.B -(A0),D0
- DBEQ D1,@next.type
-
- ADDQ.W #1,D1
- EXT.L D1
- MOVE.L D1,-(A6)
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- ( Now we need to get the AppleTalk version number )
-
- : get.AppleTalk.Version
- ( -- version )
-
- ( first check SPConfig and PortBUse )
- SPConfig C@ $0F AND
- 1 =
-
- ( port is configured for ATalk, check for PortBUse )
- PortBUse C@ 0>
- AND
-
- PortBUse C@ $0F AND
- 1 =
- AND
- IF
- ( AppleTalk .MPP is open, so get the version number )
- UTableBase @ 36 + @ ( addr of .MPP DCE )
- 7 + C@
- ELSE
- ( AppleTalk not open )
- 0
- THEN
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : call.HGetVInfo
- ( This routine used the variable array "file.iopb" and "vol.name"
- and calls the ROM routine HGetVInfo, using a passed-in volume ID.)
-
- { volume.ID @file.ioPB @vol.name -- resultcode }
-
- 0 ioCompletion .OF. @file.ioPB !
- @vol.name ioFileName .OF. @file.ioPB !
- volume.ID ioVRefNum .OF. @file.iopb W!
- 0 ioVolIndex .OF. @file.ioPB W!
- @file.iopb (CALL) HGetVInfo ( -- result )
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- : get.THE.blessed.WD
- ( This routine gets the Working directory number of the
- blessed folder that contains the current open system file -
- use this routine when SysEnvirons is not available.)
-
- ( -- WDRefNum )
-
- { | @file.ioPB -- }
-
- ( do it the hard and scary way )
-
- 122 alloc.tempmem -> @file.ioPB
-
- 0 ioCompletion .OF. @file.iopb !
- 0 ioVRefNum .OF. @file.iopb W!
- SysMap W@ ioRefNum .OF. @file.iopb W!
- 0 ioFCBIndex .OF. @file.iopb !
- @file.iopb (CALL) GetFCBInfo ( -- result.code )
- 0=
- IF
- ioVRefNum .OF. @file.iopb W@
- DUP 0=
- IF
- ( dir.ID -- )
- ( either the volume is MFS or there is no blessed
- folder on this volume )
-
- ioVSigWord .OF. @file.iopb W@
- TSigWord =
- IF
- ( it's an HFS volume with no blessed folder, so it's
- not the boot volume. Use the global BootDrive to
- find the boot drive and get it's blessed folder ID.)
- DROP
- BootDrive W@
- @file.ioPB
- 0
- ( -- vol.ID @file.ioPB @vol.name )
- call.HGetVInfo
- 0=
- IF
- ioVFndrInfo .OF. @file.iopb @
- ELSE
- ( a fatal error occurred )
- 0
- THEN
- THEN
- THEN
- ( -- dir.ID )
- ELSE
- ( a fatal error occurred )
- 0
- THEN
- dispos.tempmem
- ( -- WDRefNum )
- ;
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- CODE fake.SysEnv
- ( version @SysEnvRec -- result )
-
- MOVE.L A3,-(A7) \ save A3
-
- MOVE.L (A6)+,A3 \ get the SysEnvRec pointer
-
- setenvironsVersion
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- setmachineType \ get the Machine type
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- set.System.Version \ get the system file version
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- set.processor.type \ get the CPU type
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- set.FPU.exist \ is there a floating point processor
- MOVE.L (A6)+,D0
- MOVE.B D0,(A3)+
-
- set.Color.QD.exist \ is color QuickDraw available
- MOVE.L (A6)+,D0
- MOVE.B D0,(A3)+
-
- get.keyboard.type \ which keyboard are we using
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- get.AppleTalk.Version
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- get.THE.blessed.WD
- MOVE.L (A6)+,D0
- MOVE.W D0,(A3)+
-
- MOVE.L (A7)+,A3
- MOVE.L #-5500,(A6)
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- CODE CALL.SysEnvirons
- ( version @SysEnvRec -- result )
- is.SysEnvirons.Avail
- TST.L (A6)+
- BEQ.S @noSysEnv
-
- EXG D4,A7
- MOVE.W 6(A6),D0
- MOVE.L (A6),A0
- ADDQ.W #4,A6
- _SysEnvirons
- EXT.L D0
- MOVE.L D0,(A6)
- EXG D4,A7
- BRA @this.exit
-
- @noSysEnv
- fake.SysEnv
- @this.exit
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- CODE (CALL).SysEnvirons
- ( version @SysEnvRec -- result )
- is.SysEnvirons.Avail
- TST.L (A6)+
- BEQ.S @noSysEnv
-
- MOVE.W 6(A6),D0
- MOVE.L (A6),A0
- ADDQ.W #4,A6
- _SysEnvirons
- EXT.L D0
- MOVE.L D0,(A6)
- BRA @this.exit
-
- @noSysEnv
- fake.SysEnv
- @this.exit
- RTS
- END-CODE
- #ifdef _EMBEDDED_
- MACH
- #endif
-
- restore.VOCAB.state
-
- #endif ( COMPATIBILITY definitions )
-
-